import { getConfig } from '@/api/common';
import { getList as getAgentList } from '@/api/agent';
import { getList as getUserList } from '@/api/user';

const state = {
  config: {},
  agent: [],
  users: []
};

const mutations = {
  setConfig(state, config) {
    state.config = config;
  },
  setAgent(state, agent) {
    state.agent = agent;
  },
  setUsers(state, users) {
    state.users = users;
  }
};

const actions = {
  async getAgent({ commit }) {
    const agent = (await getAgentList({ size: 9999 })).data.list;
    commit('setAgent', agent);
  },
  async getUser({ commit }) {
    const users = (await getUserList({ size: 9999 })).data.list;
    commit('setUsers', users);
  },
  async getConfig({ commit }) {
    const cfg = (await getConfig()).data;
    commit('setConfig', cfg);
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
